package com.lq.ecoldchain.ui.recharge

import com.alibaba.android.arouter.facade.annotation.Route
import com.lq.ecoldchain.R
import com.lq.ecoldchain.base.BaseNavigator
import com.lq.ecoldchain.base.view.BaseActivity
import com.lq.ecoldchain.databinding.ActivityRecharegeBinding
import com.lq.ecoldchain.entity.AliPayBean
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.model.AliPayModel
import kotlinx.android.synthetic.main.activity_recharege.*
import org.kodein.di.Kodein
import org.kodein.di.generic.instance

/*
*2019/1/18 0018  11:18
*function by lq
*/
@Route(path = BaseNavigator.recharge)
class RechargeActivity : BaseActivity<ActivityRecharegeBinding>() {
    override val layoutId = R.layout.activity_recharege
    override val viewDelegate: RechargeDelegate by instance()

    override fun initView() {
        binding.delegate = viewDelegate
        titleText("充值")
        confirmRechargeTv.setOnClickListener { commit() }
    }

    override val kodein = Kodein.lazy {
        extend(parentKodein)
        import(recharegeKodeinModule)
    }

    fun commit() {
        BaseNetCore.ApiServiceImpl.rechargeAliPay("充值", "0.01").compose(RxTransformer.switchSchedulers()).subscribe(object : BaseObserver<AliPayBean>() {
            override fun onSuccess(t: AliPayBean?) {
                AliPayModel(this@RechargeActivity).payV2(t!!.form)
            }

            override fun onFail(code: String) {}
        })
    }

}